package com.xbs.dao.content;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.RowDatas;
/**
 * 支付全款界面dao
 * @author 余凯
 *
 */
public class PayDao extends BaseDao {
	private RowDatas<String> str;
	
	public PayDao() {
		str  = new getString();
	}
	
	/**
	 * 1.根据订单编号，更新该订单的第一次实收金额
	 * @param coid
	 * @param money
	 * @return
	 */
	public int upFirstMoney(String coid,Double money){
		String sql="update tb_common_order set co_first_pay_money="+ money+" where co_id='"+coid+"'";
		return updateExecuted(sql);
	}
	
	/**
	 * 2.根据订单编号，更新时间表的订单付款时间
	 * @param coid
	 * @param ts
	 * @return
	 */
	public int upOrderPay(String coid,Timestamp ts){
		String sql="update tb_time set time_order_pay='"+ts+"' where time_order_id='"+coid+"'";
		System.out.println(sql);
		return updateExecuted(sql);
	}
	
	/**
	 * 3.根据订单编号，更新该订单的实收金额
	 * @param coid
	 * @param money
	 * @return
	 */
	public int upFactMoney(String coid,Double money){
		String sql="update tb_common_order set co_fact_pay_money="+ money+" where co_id='"+coid+"'";
		return updateExecuted(sql);
	}
	
	/**
	 * 4.根据登录的用户的身份证号码获取他的支付密码
	 * @param id
	 * @return
	 */
	public String selPwd(String id){
		String sql = "select user_paypassword from tb_user where user_idcard='"+id+"'";
		return query(sql, str);
	}
	
	/**
	 * 5.支付成功之后修改该订单的状态
	 * @param id
	 * @param status
	 * @return
	 */
	public int upStatus(String id,String status){
		String sql="update tb_common_order set co_order_status='"+status+"' where co_id='"+id+"'";
		return updateExecuted(sql);
	}
	
	public class getString implements RowDatas<String>{
		@Override
		public String getRowData(ResultSet rs) throws SQLException {
			return rs.getString(1);
		}
	}
}
